package com.hd.openapi.servies.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hd.openapi.common.ResponseResult;
import com.hd.openapi.common.ResultTable;
import com.hd.openapi.dao.AdminUserMapper;
import com.hd.openapi.dao.RoleMapper;
import com.hd.openapi.dao.UserRoleMapper;
import com.hd.openapi.entity.AdminUser;
import com.hd.openapi.servies.servies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class serviesimpl implements servies {
    @Autowired
    private AdminUserMapper adminUserMapper;
    @Autowired
    private RoleMapper rm;

    @Override
    public AdminUser getdataall(String email, String password) {
        AdminUser getalldata = adminUserMapper.getalldata (email);
        if (getalldata!=null && getalldata.getPassword ().equals (password)) {
            return getalldata;
        }
        return null;
    }

    @Override
    public ResultTable getadminuserdata(Integer page, Integer limit,
                                        String realName, String email,
                                        Integer status) {
        PageHelper.startPage (page,limit);
        List<AdminUser> getdata = adminUserMapper.getadminusre(realName,email,status);
        PageInfo aa=new PageInfo (getdata);
        return new ResultTable (0,"msg",(int)aa.getTotal (),aa.getList ());
    }

    @Override
    public ResponseResult deletedata(Integer[] ids) {
        int i = adminUserMapper.deleteda(ids);
        return ResponseResult.getSuccess ();
    }

    @Override
    public ResponseResult add(AdminUser adminUser) {
            int i = adminUserMapper.insertSelective (adminUser);
            return ResponseResult.getSuccess ();

    }

    @Override
    public ResponseResult updatedata(AdminUser adminUser) {
        int i = adminUserMapper.updateByPrimaryKeySelective (adminUser);
        return ResponseResult.getSuccess ();
    }

    @Override
    public List<Integer> getdatauserid(Integer userId) {

        return rm.getroledata (userId);
    }

}
